<?php
/**
 * Website controller
 * @author www.ideamesh.com
 */
#ini_set("include_path",  dirname(__FILE__).":".dirname(__FILE__)."\\..:.:..:".ini_get(include_path));
set_include_path(  dirname(__FILE__).";".dirname(__FILE__)."\\..;..;".get_include_path());

//Include and instantiate Smarty
require_once('Smarty/Smarty.class.php');
require_once('lib/config.lib.php');

$smarty = new Smarty();
//Setup the url var we are looking for to control page display
$page_var = 'page';

//Using the $_REQUEST scope so that the page can be passed in via $_POST or $_GET
$page_request = isset($_REQUEST[$page_var])?$_REQUEST[$page_var]:"";
if ($page_request == '' or !isset($page_request)) $page_request="home";

$configs=loadConfigs("configs");
foreach ( $configs as $key => $value ) {
		${$key}=$value;
		$smarty->assign($key, $value);
}

//Check if the requested page was found in the menu
if ( array_key_exists ( $page_request, $templates ) )
    $template = $templates[$page_request];
    //If not set the default page
else {
     #print " Missing TEMPLATE for page $page_request";
     $template = $page_request.".tpl";
     #exit (0);
}
//Assign info to Smarty and display
$smarty->assign('template', $template);
$smarty->compile_id = "$template"."_".$page_request;
$smarty->compile_check = TRUE;
$smarty->caching = TRUE;
$smarty->cache = 2;
$smarty->cache_lifetime = 5;

## FOR DEBUGGING
#$smarty->caching = true;
#$smarty->compile_check = true;
$smarty->debugging = true;
#$smarty->debugging = false;
## END FOR DEBUGGING

#$smarty->template_dir = dirname(__FILE__)."/templates";
######$smarty->compile_dir = dirname(__FILE__)."/templates_c";
#$smarty->cache_dir =  dirname(__FILE__)."/cache";
$smarty->config_dir = dirname(__FILE__)."/configs";
$moduleDir=dirname(__FILE__)."/modules";
if(!$smarty->is_cached($smarty->compile_id)) {
	if ( file_exists($moduleDir."/".$page_request.".php") ) include_once($moduleDir."/".$page_request.".php");
	$smarty->assign('page_var', $page_var);
	$smarty->assign('page_request', $page_request);
}

$smarty->display('index.tpl', implode('_', $_REQUEST) );
?>
